﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace xhim.common.Api
{
    public class ApiResultModel
    {
        public const int OK = 200;
        public const int ERROR = 999;
        public ApiResultModel() { }
        public ApiResultModel(int code)
        {
            this.code = code;
        }
        public ApiResultModel(int code, string msg) : this(code)
        {
            this.msg = msg;
        }
        public ApiResultModel(int code, string msg, string resultCode, string resultMessage) : this(code, msg)
        {
            this.resultCode = resultCode;
            this.resultMessage = resultMessage;
        }

        public int code { get; set; }
        public string msg { get; set; }
        public string resultCode { get; set; }
        public string resultMessage { get; set; }
        public object data { get; set; }
        public string token { get; set; }
        public bool isSuccess
        {
            get { return code == OK; }
        }

        public static ApiResultModel Success()
        {
            ApiResultModel apiResultModel = new ApiResultModel(OK);
            return apiResultModel;

        }
        public static ApiResultModel Fail(string msg)
        {
            ApiResultModel apiResultModel = new ApiResultModel(ERROR, msg);
            return apiResultModel;

        }
        public static ApiResultModel Fail(int code, string msg)
        {
            ApiResultModel apiResultModel = new ApiResultModel(code, msg);
            return apiResultModel;

        }

        public static ApiResultModel Fail(int code, string msg, string resultCode, string resultMessage)
        {
            ApiResultModel apiResultModel = new ApiResultModel(code, msg, resultCode, resultMessage);
            return apiResultModel;

        }
    }
}
